package  networkSimulation.framework


/**
 * This class represents a 'bridge' between 2 Nodes of the same subtype.
 *
 * @author  Tim Caljé
 *          Jeroen De Raedt
 *          Jorick Van Aken
 */
class Edge[N <% Node](var from : N, var to : N) extends Observable with FieldExporter {

  if (!this.isValid()) {
    throw new IllegalArgumentException("Invalid edge")
  }

  /**
   * Get the color of this edge
   */
  def getColor() : String = "black"

  /**
   * get the XML representation of this edge
   */
  // We wanted this to be generic: so custom implementations of Edge don't need to make changes to this method
  // So this hack collects all the fields of the class, looks for their get-methods and builds the XML representation
  // However by doing things this way, we demand that the attributes of the Edge derivatives are public
  def toXml(): xml.Elem = {
    <edge>{
      exportFields()
    }</edge>
  }

  /**
   * Check whether this node is valid
   */
  protected def isValid() : Boolean = {
    if (this.to == null || this.from == null) {
      false
    } else {
      true
    }
  }
}